package com.hiss.basic.system.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.hiss.basic.client.system.ISysParameterService;
import com.hiss.basic.model.system.request.SysParameterCreateRequest;
import com.hiss.basic.model.system.request.SysParameterQueryRequest;
import com.hiss.basic.model.system.request.SysParameterUpdateRequest;
import com.hiss.basic.model.system.response.SysParameterQueryResponse;
import com.hiss.basic.starter.core.model.R;
import com.hiss.basic.starter.log.annotation.Log;
import com.hiss.basic.starter.log.enums.BusinessTypeEnum;
import com.mybatisflex.core.paginate.Page;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 系统参数 controller
 */
@RestController
@RequestMapping("/sys/parameter")
public class SysParameterController {

    @Resource
    private ISysParameterService sysParameterService;

    @SaCheckPermission("sys:parameter:list-page")
    @RequestMapping(value = "/list/page", method = RequestMethod.GET)
    public R<Page<SysParameterQueryResponse>> listPage(SysParameterQueryRequest request) {
        Page<SysParameterQueryResponse> pageList = sysParameterService.findPageList(request);
        return R.success(pageList);
    }

    @SaCheckPermission("sys:parameter:create")
    @Log(title = "新增参数", businessType = BusinessTypeEnum.INSERT)
    @RequestMapping(value = "create", method = RequestMethod.POST)
    public R<Void> create(@RequestBody SysParameterCreateRequest request) {
        sysParameterService.create(request);
        return R.success();
    }

    @SaCheckPermission("sys:parameter:update")
    @Log(title = "更新参数", businessType = BusinessTypeEnum.UPDATE)
    @RequestMapping(value = "update", method = RequestMethod.PUT)
    public R<Void> update(@RequestBody SysParameterUpdateRequest request) {
        sysParameterService.update(request);
        return R.success();
    }

    @SaCheckPermission("sys:parameter:remove")
    @Log(title = "删除参数", businessType = BusinessTypeEnum.DELETE)
    @RequestMapping(value = "remove", method = RequestMethod.DELETE)
    public R<Void> remove(Long id) {
        sysParameterService.remove(id);
        return R.success();
    }
}
